#pragma once
#include <functional>
#include <UIlib.h>

using namespace DuiLib;

#define MAINBAR_WIDTH 60     // mainbar宽度
#define MAINBAR_HEIGHT 30    // mainbar高度
#define SPE_MAINBAR_CANVAS 2 // mainbar 和 画布间隔
#define SPE_MAINBAR_SUNBAR 2 // mainbar 和 subbar间隔

class SelectWnd : public WindowImplBase
{
public:
    typedef std::function<void(HWND)> OnSelectCallback;

    SelectWnd();
    ~SelectWnd();

    static HBITMAP sCurBitmap;
    static SelectWnd *instance;
    static void StartCapture(OnSelectCallback cb);

    RECT GetWindowRect() const;
    RECT GetClipPadding() const;
    void SetClipPadding(RECT rc);
    RECT GetClipRect() const;
    RECT GetCanvasContainerRect() const;
    void RefreshClipWinSize();

    void ShowClipBorder();

public:
    CControlUI *CreateControl(LPCTSTR pstrClass);
    virtual void OnFinalMessage(HWND);
    DuiLib::CDuiString GetSkinFile();
    LPCTSTR GetWindowClassName() const;
    UINT GetClassStyle() const;
    void InitWindow();
    LRESULT HandleCustomMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);

    void Notify(TNotifyUI &msg);
    void OnClick(CControlUI *pControl);

private:
    OnSelectCallback m_onSelectCallback;
    HWND m_selectedWnd;

    CControlUI *m_pDesktopImage;
    CControlUI *m_pDesktopMask;
    CControlUI *m_pDesktopMaskBorder;
    CContainerUI *m_pDesktopCanvasContainer;

    RECT m_rcWindow;
    RECT m_rcClipPadding;
    POINT m_ptClipBasePoint; // 调整基准点
    bool m_bClipChoiced;     // 是否已选择截图区域
    bool m_isSubOnBottom;    // sub在main下边缘
    TCHAR m_sClipDrawStringBuf[MAX_PATH];
};